package com.ld.security.common.shiro.Interceptor;

import com.ld.security.common.shiro.anno.IgnoreUserToken;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.annotation.Annotation;

public abstract class BaseInterceptor implements HandlerInterceptor {

    public abstract String getName();

    protected <E extends Annotation> E getAnno(Object handler, Class<E> clazz){
        if(handler instanceof  HandlerMethod){
            HandlerMethod handlerMethod = (HandlerMethod) handler;

            E annotation = handlerMethod.getBeanType().getAnnotation(clazz);

            if(annotation == null){
                annotation =  handlerMethod.getMethodAnnotation(clazz);
            }
            return annotation;
        }

       return null;
    }

}
